using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace Commerce.Common
{
    /// <summary>
    /// Controller class for IntegrationAddress
    /// </summary>
    [System.ComponentModel.DataObject]
    public partial class IntegrationAddressController
    {
        // Preload our schema..
        IntegrationAddress thisSchemaLoad = new IntegrationAddress();
        private string userName = string.Empty;
        protected string UserName
        {
            get
            {
				if (userName.Length == 0) 
				{
    				if (System.Web.HttpContext.Current != null)
    				{
						userName=System.Web.HttpContext.Current.User.Identity.Name;
					}

					else
					{
						userName=System.Threading.Thread.CurrentPrincipal.Identity.Name;
					}

				}

				return userName;
            }

        }

        [DataObjectMethod(DataObjectMethodType.Select, true)]
        public IntegrationAddressCollection FetchAll()
        {
            IntegrationAddressCollection coll = new IntegrationAddressCollection();
            Query qry = new Query(IntegrationAddress.Schema);
            coll.LoadAndCloseReader(qry.ExecuteReader());
            return coll;
        }

        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public IntegrationAddressCollection FetchByID(object AddressId)
        {
            IntegrationAddressCollection coll = new IntegrationAddressCollection().Where("addressId", AddressId).Load();
            return coll;
        }

		
		[DataObjectMethod(DataObjectMethodType.Select, false)]
        public IntegrationAddressCollection FetchByQuery(Query qry)
        {
            IntegrationAddressCollection coll = new IntegrationAddressCollection();
            coll.LoadAndCloseReader(qry.ExecuteReader()); 
            return coll;
        }

        [DataObjectMethod(DataObjectMethodType.Delete, true)]
        public bool Delete(object AddressId)
        {
            return (IntegrationAddress.Delete(AddressId) == 1);
        }

        [DataObjectMethod(DataObjectMethodType.Delete, false)]
        public bool Destroy(object AddressId)
        {
            return (IntegrationAddress.Destroy(AddressId) == 1);
        }

        
        
    	
	    /// <summary>
	    /// Inserts a record, can be used with the Object Data Source
	    /// </summary>
        [DataObjectMethod(DataObjectMethodType.Insert, true)]
	    public void Insert(int? OrderId,string AddressType,string FirstName,string LastName,string Email,string Address1,string Address2,string City,string State,string Zip,string Country,string Phone,DateTime? CreatedOn,string CreatedBy,DateTime? ModifiedOn,string ModifiedBy)
	    {
		    IntegrationAddress item = new IntegrationAddress();
		    
            item.OrderId = OrderId;
            
            item.AddressType = AddressType;
            
            item.FirstName = FirstName;
            
            item.LastName = LastName;
            
            item.Email = Email;
            
            item.Address1 = Address1;
            
            item.Address2 = Address2;
            
            item.City = City;
            
            item.State = State;
            
            item.Zip = Zip;
            
            item.Country = Country;
            
            item.Phone = Phone;
            
            item.CreatedOn = CreatedOn;
            
            item.CreatedBy = CreatedBy;
            
            item.ModifiedOn = ModifiedOn;
            
            item.ModifiedBy = ModifiedBy;
            
	    
		    item.Save(UserName);
	    }

    	
	    /// <summary>
	    /// Updates a record, can be used with the Object Data Source
	    /// </summary>
        [DataObjectMethod(DataObjectMethodType.Update, true)]
	    public void Update(int AddressId,int? OrderId,string AddressType,string FirstName,string LastName,string Email,string Address1,string Address2,string City,string State,string Zip,string Country,string Phone,DateTime? CreatedOn,string CreatedBy,DateTime? ModifiedOn,string ModifiedBy)
	    {
		    IntegrationAddress item = new IntegrationAddress();
		    
				item.AddressId = AddressId;
				
				item.OrderId = OrderId;
				
				item.AddressType = AddressType;
				
				item.FirstName = FirstName;
				
				item.LastName = LastName;
				
				item.Email = Email;
				
				item.Address1 = Address1;
				
				item.Address2 = Address2;
				
				item.City = City;
				
				item.State = State;
				
				item.Zip = Zip;
				
				item.Country = Country;
				
				item.Phone = Phone;
				
				item.CreatedOn = CreatedOn;
				
				item.CreatedBy = CreatedBy;
				
				item.ModifiedOn = ModifiedOn;
				
				item.ModifiedBy = ModifiedBy;
				
		    item.MarkOld();
		    item.Save(UserName);
	    }

    }

}

